import time
import re

query = ''
def watch(fn):
    fp = open(fn, 'r')
    while True:
        new = fp.readline()
        # Once all lines are read this just returns ''
        # until the file changes and a new line appears

        if new:
            parts = re.split("({executed in )(\d*)( msec})", new)
            if len(parts) < 3:
                query = new
                continue
            if int(parts[2]) >= 500:
                qparts = re.split("(^\d*\.)",query)
                yield (parts[2], qparts[2].rstrip())
        else:
            time.sleep(0.5)

fn = 'C:\DEV\workspace\CDSModel\sql.log'

for time_taken, hit_sentence in watch(fn):
    print "Time taken %r in line: %r" % (time_taken, hit_sentence)
